<html>
<head><meta charset="utf-8"><title>fmt::Arguments API change · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html">fmt::Arguments API change</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="209797660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/209797660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lurker <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#209797660">(Sep 11 2020 at 15:44)</a>:</h4>
<p>A recent commit at <a href="https://github.com/rust-lang/rust/pull/74056">https://github.com/rust-lang/rust/pull/74056</a> seems to have "broken" the runtime-fmt crate (<a href="https://docs.rs/runtime-fmt/0.4.1/runtime_fmt/">https://docs.rs/runtime-fmt/0.4.1/runtime_fmt/</a>). This was relying on unstable APIs (<code>new_v1_formatted()</code> and <code>new_v1()</code>), so it isn't a surprise it is now in this state. The error it spits out is:</p>
<div class="codehilite"><pre><span></span><code>error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
   --&gt; src/lib.rs:265:33
</code></pre></div>


<p>And this is because libstd's <code>Arguments</code> now accepts a <code>pieces: &amp;'a [&amp;'static str]</code> in <code>new_v1_formatted()</code>/<code>new_v1()</code>, instead of a <code>pieces: &amp;'a [&amp;'a str]</code>.</p>
<p>However, I'm unable to find an alternative to this. Aside from completely changing the runtime-fmt crate. Any thoughts on this?</p>



<a name="209798322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/209798322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lurker <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#209798322">(Sep 11 2020 at 15:49)</a>:</h4>
<p>Or my main concern, was this something that was being accidentally "supported" that's no longer supported?</p>



<a name="209799026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/209799026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#209799026">(Sep 11 2020 at 15:55)</a>:</h4>
<p>Moving this over to <a class="stream" data-stream-id="219381" href="/#narrow/stream/219381-t-libs">#t-libs</a></p>



<a name="209799045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/209799045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Notification Bot <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#209799045">(Sep 11 2020 at 15:55)</a>:</h4>
<p>This topic was moved here from <a class="stream-topic" data-stream-id="182449" href="/#narrow/stream/182449-t-compiler.2Fhelp/topic/fmt.3A.3AArguments.20API.20change">#t-compiler/help &gt; fmt::Arguments API change</a> by <span class="user-mention silent" data-user-id="116122">simulacrum</span></p>



<a name="209801201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/209801201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#209801201">(Sep 11 2020 at 16:11)</a>:</h4>
<p><span class="user-mention" data-user-id="317934">@Lurker</span> You can pass non-<code>'static</code> strings via <code>args</code> instead of <code>pieces</code>.</p>



<a name="209801461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/209801461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#209801461">(Sep 11 2020 at 16:13)</a>:</h4>
<p>The rationale for changing the lifetime to <code>'static</code> is that it allows libraries using <code>as_str</code> (e.g. loggers) to pass the string to other threads without needing to worry about lifetimes.</p>



<a name="209803733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/209803733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lurker <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#209803733">(Sep 11 2020 at 16:30)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> Indeed, but in this case, the <code>runtime-fmt</code> crate is sort of mimicking the underlying API - it composes its own <code>pieces</code>, <code>args</code> and <code>fmt</code> to later pass it to <code>Arguments::new_v1_formatted()</code> and <code>Arguments::new_v1()</code>.</p>



<a name="209803748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/209803748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lurker <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#209803748">(Sep 11 2020 at 16:30)</a>:</h4>
<p>It was fine while <code>pieces</code> was a slice of <code>&amp;'a str</code>, but now it's a slice of <code>&amp;'static str</code>, I'm not seeing a way to change the way <code>pieces</code> are handled without changing the API.</p>



<a name="209809136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/209809136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#209809136">(Sep 11 2020 at 17:17)</a>:</h4>
<p>Can't you just inject a new arg between the existing ones?</p>



<a name="209871837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/209871837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#209871837">(Sep 12 2020 at 08:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="317934">Lurker</span> <a href="#narrow/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change/near/209798322">said</a>:</p>
<blockquote>
<p>Or my main concern, was this something that was being accidentally "supported" that's no longer supported?</p>
</blockquote>
<p>Looks like it, yes -- that is basically true for any use of unstable APIs that are not actually intended to be stabilized.</p>



<a name="209871895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/209871895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#209871895">(Sep 12 2020 at 08:53)</a>:</h4>
<p>and these functions are <code>doc(hidden)</code> and don't have a tracking issue, so... quite clearly not intended for stabilization ;)</p>



<a name="209871935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/209871935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#209871935">(Sep 12 2020 at 08:54)</a>:</h4>
<p>I assume those functions will be made private once macro hygiene is good enough to support that</p>



<a name="210002755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/210002755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lurker <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#210002755">(Sep 14 2020 at 13:19)</a>:</h4>
<p>Thanks, this is the downside of building on unstable APIs. I think longer term I'll move away from runtime-fmt since it is becoming harder to keep up to date with nightly and with new bumps I end up needing to fix something.</p>



<a name="210004602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/210004602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lurker <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#210004602">(Sep 14 2020 at 13:28)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> I had a look but I don't see how that'd be possible. The <code>args</code> are just a list of <code>Argument</code>s, which has an <code>position</code> and a <code>format</code>:</p>
<div class="codehilite"><pre><span></span><code>pub struct Argument&lt;&#39;a&gt; {
   pub position: Position&lt;&#39;a&gt;,
   pub format: FormatSpec&lt;&#39;a&gt;,
}
</code></pre></div>


<p>So I don't see an easy way of just chuck in a  <code>piece</code> (of <code>str</code> type) into a slice of <code>Argument</code>s. Unless I'm misunderstanding.</p>



<a name="210005890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/210005890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#210005890">(Sep 14 2020 at 13:38)</a>:</h4>
<p>I'd recommend notifying the maintainer, but it's to be expected. Arguments is mostly not intended to be touched directly, you're only really supposed to use <code>format_args!</code> and now I guess <code>as_str</code>. It's on the maintainer's head, more or less, for exposing an unstable API.</p>



<a name="210011999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/210011999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#210011999">(Sep 14 2020 at 14:22)</a>:</h4>
<p><span class="user-mention" data-user-id="317934">@Lurker</span> It's a list of <code>ArgumentV1</code> which holds an opaque type and a function pointer to format it.</p>



<a name="210031654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/210031654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#210031654">(Sep 14 2020 at 16:43)</a>:</h4>
<p><span class="user-mention" data-user-id="317934">@Lurker</span> <a href="https://github.com/rust-lang/rust/pull/74056#issuecomment-659612289">see here</a> for some code that creates an <code>ArgumentV1</code> from <code>&amp;str</code></p>



<a name="210398271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/210398271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lurker <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#210398271">(Sep 17 2020 at 14:32)</a>:</h4>
<p>Good point, I was looking into <code>runtime-fmt</code>s Argument struct itself, but if abstract over I should be able to compose a <code>runtime-fmt</code> Piece / Argument and then push that into the stdlib's <code>Arguments</code> itself.</p>



<a name="210398476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/fmt%3A%3AArguments%20API%20change/near/210398476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lurker <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/fmt.3A.3AArguments.20API.20change.html#210398476">(Sep 17 2020 at 14:34)</a>:</h4>
<p><span class="user-mention" data-user-id="281757">@Jubilee</span> I'll contact the maintainer, but was looking for a quick fix first as the maintainer seems absent (issue <a href="https://github.com/SpaceManiac/runtime-fmt/issues/13">https://github.com/SpaceManiac/runtime-fmt/issues/13</a>, for example, has been open for a while).</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>